package com.spark.market.controller;

import com.spark.market.api.request.UserLoginParam;
import com.spark.market.api.request.UserRegisterParam;
import com.spark.market.api.utils.ResponseResult;
import com.spark.market.api.utils.ResponseUtil;
import com.spark.market.common.utils.AssertUtils;
import com.spark.market.dal.entity.UserInfoDo;
import com.spark.market.service.UserCmdCoreService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("user/cmd")
public class UserCmdController extends BaseController{
    @Resource
    private UserCmdCoreService userCmdCoreService;

    @PostMapping(value = "register")
    public ResponseResult<Object> register(@RequestBody UserRegisterParam param){
        AssertUtils.isNotNull(param,"UserRegisterParam is null");
        userCmdCoreService.register(param);
        return ResponseUtil.createSuccessResult(null,"register success");
    }

    @PostMapping(value = "login")
    public ResponseResult<UserInfoDo> login(@RequestBody UserLoginParam param){
        AssertUtils.isNotNull(param, "UserLoginParam is null");
        return ResponseUtil.createSuccessResult(userCmdCoreService.login(param), "Login success");
    }
}
